package com.aaa.sbms.service;

import com.aaa.sbms.dao.SalDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SalServiceImpl implements SalService {

    @Autowired(required = false)
    private SalDao salDao;

    @Override
    public Map positions() {
        Map resultMap = new HashMap();
        List<Map> list = salDao.positions();
        resultMap.put("list",list);
        return resultMap;
    }

    @Override
    public Map salPage(Map map) {
        int pageNo = Integer.valueOf(map.get("pageNo").toString());
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        int begin = (pageNo-1)*pageSize;
        map.put("begin",begin);
        map.put("pageSize",pageSize);
        List<Map> page = salDao.salPage(map);
        int total = salDao.salPageCount(map);
        Map resultMap= new HashMap();
        resultMap.put("list",page);
        resultMap.put("total",total);
        return resultMap;
    }

    @Override
    public Map salOnTimePage(Map map) {
        int pageNo = Integer.valueOf(map.get("pageNo").toString());
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        int begin = (pageNo-1)*pageSize;
        map.put("begin",begin);
        map.put("pageSize",pageSize);
        List<Map> page = salDao.salOnTimePage(map);
        int total = salDao.salOnTimePageCount(map);
        Map resultMap= new HashMap();
        resultMap.put("list",page);
        resultMap.put("total",total);
        return resultMap;
    }

    @Override
    public Map salOne(int id) {
        Map resultMap = new HashMap();
        Map list = salDao.salOne(id);
        resultMap.put("list",list);
        return resultMap;
    }

    @Override
    public int updateSal(Map map) {
        return salDao.updateSal(map);
    }
}
